import requests, json


class YunPian(object):
    def __init__(self, api_key):
        self.api_key = api_key
        self.single_send_url = "https://sms.yunpian.com/v2/sms/single_send.json"

    def send_sms(self, code, mobile):
        parmas = {
            "apikey": self.api_key,
            "mobile": mobile,
            'text': '【享恋科技】您的验证码是{code}'.format(code=code)
        }
        r = requests.post(self.single_send_url, data=parmas)
        return json.loads(r.text)


if __name__ == "__main__":
    yun_pian = YunPian("a69dde9d5dabfeb5bd6003dbd1a7148b")
    yun_pian.send_sms('2018', '15313433271')
